function useGameState() {
    const [gameStarted, setGameStarted] = React.useState(false);
    const [playerName, setPlayerName] = React.useState('');
    const [currentLevel, setCurrentLevel] = React.useState(1);

    const handleGameStart = (name) => {
        try {
            setPlayerName(name);
            setGameStarted(true);
            updateLastPlayed(name);
            soundManager.playBGM();
        } catch (error) {
            reportError(error);
        }
    };

    const handleBackToHome = (loadScores) => {
        try {
            setGameStarted(false);
            setCurrentLevel(1);
            loadScores(); // Refresh scores when returning to home
        } catch (error) {
            reportError(error);
        }
    };

    const handleLevelChange = (level) => {
        setCurrentLevel(level);
    };

    return {
        gameStarted,
        playerName,
        currentLevel,
        handleGameStart,
        handleBackToHome,
        handleLevelChange
    };
}
